const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fitnessPicSrc: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const baseUrl = app.globalData.baseUrl;
    const fitnessPicSrc = wx.getStorageSync("fitnessPicSrc");
    this.setData({
      fitnessPicSrc: baseUrl + '/file/' + fitnessPicSrc
    });
  },
  uploadPicture: function() {
    const that = this;
    const openId = app.globalData.openId;
    const url = app.globalData.url;
    const baseUrl = app.globalData.baseUrl;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: url + '/coach/uploadPicture/' + openId,
          filePath: tempFilePaths[0],
          name: 'file',
          success: function(response) {
            const returnObj = JSON.parse(response.data);
            if (returnObj.success) {
              that.setData({
                fitnessPicSrc: baseUrl + '/file/' + returnObj.content
              });
              wx.showToast({
                title: '上传成功',
                icon: 'none'
              })
            } else {
              wx.showToast({
                title: returnObj.message,
                icon: 'none'
              })
            }
          }
        })
      }
    })
  }
})